package factory.kotlinMode.simpleFactory

import factory.kotlinMode.Computer

/**
 * 使用单例代替工厂类
 */
object ComputerFactoryInstance {
    fun create(computerType: ComputerType): Computer {
        return when (computerType) {
            ComputerType.PC -> PC("个人电脑,cpu i7")
            ComputerType.SERVER -> Sever("服务器,cpu i9")
        }
    }

    operator fun invoke(computerType: ComputerType): Computer {
        return when (computerType) {
            ComputerType.PC -> PC("个人电脑,cpu i7")
            ComputerType.SERVER -> Sever("服务器,cpu i9")
        }
    }
}